﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Text;
using CloudTaobao.Util;

namespace CloudTaobao
{
    public partial class OAuthLoginPage : PhoneApplicationPage
    {
        private const string ttid = "400000_12258862@yqft_windowsphone7_1.0.0";
        public OAuthLoginPage()
        {
            InitializeComponent();
            //web.Source = new Uri("http://container.api.tbsandbox.com/container?appkey=12258862");
            web.Source = new Uri("http://container.open.taobao.com/container?appkey=12258862");
            //UriBuilder uri = new UriBuilder("api.m.taobao.com");
            //uri.Query = "imei=35367904047306201&imsi=4600009M0M1M2M3ABCD&ttid=400000_12258862@yqft_windowsphone7_1.0.0";
            //web.Source = uri.Uri;

            web.Navigating += new EventHandler<NavigatingEventArgs>(web_Navigating);
        }

        void web_Navigating(object sender, NavigatingEventArgs e)
        {
            if (e.Uri.Host.Equals("www.xyeshidai.com"))
            {
                NavigationService.Navigate(new Uri("/MainFunctionPage.xaml" + e.Uri.Query, UriKind.Relative));

                /*
                string query = HttpUtility.UrlDecode(e.Uri.Query);
                string noPreQuery = query.Substring(1, query.Length-1);
                IDictionary<string, string> parameters = new Dictionary<string, string>();
                string[] pairs = noPreQuery.Split(new char[]{'&'});
                foreach(string pair in pairs){
                    string[] splitedPair = pair.Split(new char[] { '=' });
                    parameters.Add(splitedPair[0], splitedPair[1]);
                }
                return;
                 * */

            }
        }

        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);
        }
    }
}